package syslt

import (
	"math/rand"
	"strings"

	"github.com/pmylund/sortutil"
)

func NewK3(bzSeed int) *K3 {
	return &K3{bzSeed: bzSeed}
}

type K3 struct {
	bzSeed int //豹子概率
}

func (k *K3) GenerateCode() (code string) {
	kList := make([]int, 0, 3)
	randSeek := rand.Intn(100)
	if randSeek <= k.bzSeed {
		kList = k.getBZ()
	} else {
		kList = k.getRandom()
	}
	sortutil.Asc(kList)
	return strings.Join(IntSliceToString(kList), ",")
}

func (k *K3) getRandom() (ls []int) {
	for a := 0; a < 3; a++ {
		n := rand.Intn(6) + 1
		ls = append(ls, n)
	}
	return
}

func (k *K3) getBZ() (ls []int) {
	ls = make([]int, 0, 3)
	for {
		n := rand.Intn(6) + 1
		if len(ls) == 3 {
			break
		}
		if len(ls) >= 1 && ls[0] != n {
			continue
		}
		ls = append(ls, n)
	}
	return
}
